import uuid
import netifaces
import os

def get_mac_addresses_netifaces():
    mac_addresses = {}
    for interface in netifaces.interfaces():
        print(interface)
        addrs = netifaces.ifaddresses(interface)
        try:
            mac_addresses[interface] = addrs[netifaces.AF_LINK][0]['addr']
        except (KeyError, IndexError):
            continue
    return mac_addresses

# print('所有网络接口的 MAC 地址 (通过 netifaces):')
# print(netifaces.ifaddresses('enp7s0f5'))

def loadMac():
    mac_address = uuid.UUID(int=uuid.getnode()).hex[-12:].upper()
    # print(mac_address)
    mac_address = ":".join(
        [mac_address[i : i + 2] for i in range(0, 11, 2)]
    ).lower()
    # print(mac_address)
    return mac_address

def loadLinuxMac():
    macs = get_mac_addresses_netifaces()
    for key in macs:
        if key == 'eth0':
            return macs[key]
        elif str(key).startswith('en'):
            return macs[key]
        else:
            continue
    return loadMac()

# 获得主板sn号
def loadSn():
	sn = os.popen("sudo dmidecode -s baseboard-serial-number | awk '{print $0}'").readlines()
	return sn[0].strip()

# print("当前机器的主板序列号：", loadSn())
